package apis

import (
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-admin-team/go-admin-core/sdk/api"
	"tuowei.com/app/admin/models"
	"tuowei.com/app/other/service/dto"
	cDto "tuowei.com/common/dto"
	"tuowei.com/pkg/xlog"
)

type Subject struct {
	api.Api
}

func (s Subject) GetSubjectList(c *gin.Context) {
	req := dto.GetSubjectListRequest{}
	err := s.MakeContext(c).
		MakeOrm().
		Bind(&req, binding.Default(c.Request.Method, c.ContentType())).
		Errors
	if err != nil {
		xlog.Error(err)
		s.Error(500, err, err.Error())
		return
	}
	var model models.SysSubject
	var list []*SubjectList
	err = s.Orm.Model(&model).Scopes(cDto.MakeCondition(req.GetNeedSearch())).Find(&list).Error
	if err != nil {
		s.Error(200, err, "数据库查询错误")
	}
	s.OK(&list, "OK")
	return
}

type SubjectList struct {
	Id       int    `json:"id"`
	Name     string `json:"name"`
	Province string `json:"province" gorm:"type:varchar(20);comment:适用地区" ` //适用区域
}
